package dao;

import java.util.LinkedList;
import java.util.List;
import entities.Video;

public class VideoDAO {

	private static final VideoDAO instance = new VideoDAO();
	private List<Video> Videos;
	
	private VideoDAO(){
		Videos = new LinkedList<Video>();
		Video cus = null;
		
	cus = Video.newInstance("<embed src=\"./player/player.swf\" width=\"349\" height=\"239\" allowscriptaccess=\"always\" allowfullscreen=\"true\" flashvars=\"height=239&width=349&file=acera.flv&backcolor=0xf7f7f7&frontcolor=0x333333&lightcolor=0xd6e14&screencolor=0xEEEEEE&searchbar=false&autostart=true\"</embed>",
				"Action", "A great action movie.", 1000L, "14.95", "11/12/08", "Movie 1", "5:45", "01/05/99", ".mpg", 100, "<td colspan=\"3\" width=\"122\"><a href=\"./ViewVideo\"><img id=\"Picture5\" height=\"122\" width=\"122\" src=\"./images/video1.jpg\" border=\"0\" alt=\"mvstore_21\" title=\"mvstore_21\"></a></td>");
		Videos.add(cus );
		cus = Video.newInstance("<embed src=\"./player/player.swf\" width=\"349\" height=\"239\" allowscriptaccess=\"always\" allowfullscreen=\"true\" flashvars=\"height=239&width=349&file=acera.flv&backcolor=0xf7f7f7&frontcolor=0x333333&lightcolor=0xd6e14&screencolor=0xEEEEEE&searchbar=false&autostart=true\"</embed>",
				"Drama", "A great drama movie.", 1001L, "14.95", "11/11/07", "Movie 2", "15:05", "01/15/99", ".mpg", 100, "<td colspan=\"2\" width=\"122\"><a href=\"./ViewVideo\"><img id=\"Picture6\" height=\"122\" width=\"122\" src=\"./images/video2.jpg\" border=\"0\" alt=\"mvstore_23\" title=\"mvstore_23\"></a></td>");
		Videos.add(cus );
		cus = Video.newInstance("<embed src=\"./player/player.swf\" width=\"349\" height=\"239\" allowscriptaccess=\"always\" allowfullscreen=\"true\" flashvars=\"height=239&width=349&file=acera.flv&backcolor=0xf7f7f7&frontcolor=0x333333&lightcolor=0xd6e14&screencolor=0xEEEEEE&searchbar=false&autostart=true\"</embed>",
				"Drama", "A great comedy movie.", 1002L, "14.95", "09/14/03", "Movie 3", "45:00", "03/25/08", ".mpg", 100, "<td colspan=\"2\" width=\"122\"><a href=\"./ViewVideo\"><img id=\"Picture7\" height=\"122\" width=\"122\" src=\"./images/video3.jpg\" border=\"0\" alt=\"mvstore_25\" title=\"mvstore_25\"></a></td>");
		Videos.add(cus );
	}
	
	public static VideoDAO getInstance() {
		return instance;
	}

	public synchronized Video findVideo(Long product_id) {
		Video result = null;
		for (Video s : Videos){
			if (s.getProduct_id().equals(product_id)){
				result = s;
			}
		}
		return result;
	}

	public synchronized void addVideo(Video obj) throws RecordDuplicateException{
		if (findVideo(obj.getProduct_id()) != null){
			throw new RecordDuplicateException("Video with id: " + obj.getProduct_id() + " is already in the db.");
		}
		else {
			Videos.add(obj);
		}
	}

}
